import javax.sound.sampled.*;
import java.net.*;

public class AudioSender {
    public static void main(String[] args) throws Exception {
        String targetIP = "192.254.5.197";  // 这里直接指定接收端的 IP 地址
        int targetPort = 50005;            // 可以在这里直接指定端口号

        InetAddress address = InetAddress.getByName(targetIP);
        DatagramSocket socket = new DatagramSocket();

        TargetDataLine line = AudioUtil.getTargetDataLine();
        line.start();


        byte[] buffer = new byte[1024];
        while (true) {
            int bytesRead = line.read(buffer, 0, buffer.length);
            DatagramPacket packet = new DatagramPacket(buffer, bytesRead, address, targetPort);
            System.out.println("Sending packet with size: " + bytesRead);
            socket.send(packet);
            System.out.println("Packet sent");
        }
    }
}
